package com.base.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLEncoder;

/**
 * @Author mzl.
 */
public class EncodingUtils {

    private static final Logger LOG = LoggerFactory.getLogger(EncodingUtils.class);

    public static String getUTF8forString(String data) {
        try {
            String utf8data = new String(data.getBytes("UTF-8"));
            return URLEncoder.encode(utf8data, "UTF-8");
        } catch (Exception e) {
            LOG.error("字符串转UTF-8失败", e);
            return null;
        }
    }

}
